package network.udp.udp_send_all;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

/**
 * @program: baseModule
 * @description:
 * @author: zhanghz001
 * @create: 2020-10-26 16:39
 **/
public class AllReceive {
    public static void main(String[] args) {
        receive();
    }

    private static void receive() {
        DatagramSocket socket = null;
        try {
            //建立连接
            socket = new DatagramSocket(10000);

            //数据接收
            byte[] bytes = new byte[1024];
            DatagramPacket packet = new DatagramPacket(bytes, bytes.length);

            //接收数据
            socket.receive(packet);
            System.out.println(new String(packet.getData(), 0, packet.getLength()));

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            //关闭io
            if (socket != null) {
                socket.close();
            }
        }
    }
}
